

#VPATH = 

# ........ makefile

REV=$(shell svnversion | sed 's/.*://' | sed 's/M//')

HARDWARE = HARDWARE__SH_CPU

Target = SmartDin.r$(REV).hex
SourceList = main.c SysClock.c Interrupt.c app.c String.c Init.c UART.c #my_macros.c
SourceList += printf.c atd.c
#MicroType = 16F690
MicroType = 18F25K20
# http://ww1.microchip.com/downloads/en/DeviceDoc/41303G.pdf

MACROS = -D__APP_DEBUG__ -DREVISION=$(REVISION) -D$(HARDWARE) #-D$(SH_DEVICE)

def f = pipe

#CC = C:/PROGRA~1/HI-TEC~1/PICC/std/9.60/bin/picc.exe
#CC = C:/PROGRA~1/HI-TEC~1/PICC/9.70/bin/picc.exe
#CC = C://PROGRA~1//HI-TEC~1//PICC-18//PRO//9.63//bin//picc18.exe 
CC = picc18

CFLAGS = --pass1 -P -q --runtime=default --opt=all -D__DEBUG=1 -g
CFLAGS +=  "--errformat=%f: %l: (%n) %s"
# CFLAGS += "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"


LDFLAGS = --summary=default --output=default -P --runtime=default --opt=all -D__DEBUG=1 -g
LDFLAGS += "--errformat=%f: %l: (%n) %s" "--msgformat=Advisory[%n] %s"
# LDFLAGS +=  "--warnformat=Warning [%n] %f; %l.%c %s"

ObjectList = $(patsubst %.c, %.p1, $(SourceList)) 


all: c $(Target) copy 

$(Target) : $(ObjectList) 
	$(CC) $^ -O$@ $(LDFLAGS) --chip=$(MicroType) #-L-pSer_Num=0x06B0

# $(Target) : $(ObjectList) 
# 	$(CC) -E $^ -O$@ -Q -$(MicroType) -L-pSerNum=0x06B0
# #	WinPic800.exe -p -s -dPIC$(MicroType) $(Target)
# #	D:\PROGRA~1\Soft-Log\IcpWin\ICP_Win.exe $(Target) /p


# %.obj : %.c *.h
# 	$(CC) -C -E $< -O$@ -Zg9 -O -Q -$(MicroType)

%.p1 : %.c *.h
	$(CC) $< -O$@ -Q $(CFLAGS) $(MACROS) --chip=$(MicroType) 


c: 
	rm -f *.obj *.lst *.sdb *.p1 *.pre *.hxl *.sym *.rlf *.cof *.d *.as
	rm -f $(Target) 

e:
	etags *.c *.h

serial: PIC18_Serialization.exe
	./PIC18_Serialization.exe $(Target)

p: $(Target) #serial 
	@echo "       ======== PROGRAMMING ============"
	pk2cmd -W -V8 -PPIC$(MicroType) -E -F$(Target) -M -Y -K -I -R 

#C:/PK2CMD/pk2cmd.exe -W -V12 -PPIC$(MicroType) -E -F$(Target) -M -Y -K -I -R 
#	C:\WinPic800\WinPic800.exe -p -s -dPIC$(MicroType) $(Target)
#	D:\PROGRA~1\Soft-Log\IcpWin\ICP_Win.exe $(Target) /p
#	pk2cmd -A5 -V12 -PPIC$(MicroType) -E -F$(Target) -M -Y -K -I


copy:
	cp $(Target) ../download

ifeq ($(f),p)
prog: p
	echo
else
prog: 
	@echo
endif


b : $(Target) serial prog


# QA_WORK_VER = Z:/Development/SimPhony_V3_QA/SimPhony_Versions/Work_Version

# alld: $(Target) smd
# 	bash $(VPATH)/CreateDir.sh $(QA_WORK_VER)
# 	cp $(Target) $(QA_WORK_VER) 
# 	bash ../Utilites/h2h.sh $(BOOT_LOADER) $(Target) > $(FULL)
# 	unix2dos $(FULL)
# 	cp $(FULL) $(QA_WORK_VER) 
# 	./CLEAN.BAT

# smd:
# #	echo $(QA_WORK_VER) | email -s "Versions Update - TEST-11" dimitrip@cellnets.com,dima.development@gmail.com
# 	bash ../SimPhony_Basic/sendEMail.sh $(QA_WORK_VER)


.PHONY : c e p b prog

















#######################################################


# #VPATH = ../SimPhony_Basic
# .PHONY: c p e all
# #COMMON_PATH = ..\SimPhony_Basic

# NAME = SH18_PCTR
# LABEL = 
# VERSION = _1-204
# SUFFIX = __00.hex

# LANGUAGE = LANGUAGE_SPAN 
# COUNTRY = COUNTRY__MEXICO
# TEST_MODE = 

# OPTIONS_3 = NO_INSTALLER_MESSAGE

# # ifeq ($(HARDWARE), HARDWARE__VIA_SMC)
# # MODEM_TYPE = MODEM_TYPE__SIMCOM
# # # MODEM_TYPE = MODEM_TYPE__MC55I
# # DISPLAY = LCD__GRAPHICAL
# # CV = COIN_VALIDATOR
# # COINS_MAX = 2
# # COINS_OPTION = _C$(COINS_MAX)
# # HW = _VIA_SMC
# # else
# # ifeq ($(HARDWARE), HARDWARE__SIM_LITE)
# # MODEM_TYPE = MODEM_TYPE__SIMCOM
# # HW = _SIM_LITE
# # else
# # ifeq ($(HARDWARE), HARDWARE__HOME_PHONE)
# # MODEM_TYPE = MODEM_TYPE__SIMCOM
# # DISPLAY = LCD__GRAPHICAL
# # HW = _HOME
# # else
# # HARDWARE = HARDWARE__SIMPHONY_100
# # HW = 100
# # endif
# # endif
# # endif

# # ifeq ($(MODEM_TYPE), MODEM_TYPE__SIMCOM) 
# # Offset = 0x3000
# # #LABEL = SIMCOM
# # BOOT_LOADER =../BootLoader/Firmware/BootLoader_SIMCOM_.hex
# # else
# # ifeq ($(MODEM_TYPE), MODEM_TYPE__MC55I)
# # Offset = 0x3000
# # LABEL = MC55I
# # BOOT_LOADER =../BootLoader/Firmware/BootLoader_SIMCOM_.hex
# # else
# # Offset = 0x2600
# # BOOT_LOADER =../BootLoader/Firmware/BootLoader.hex
# # endif
# # endif

# #dont send message SMS if phone can not accept the input SMS 
# SMS_NOTIFICATION = DONT_SEND_SMS_NOTIFICATION

# # ifeq ($(TEST_MODE), QUICK_TEST)
# # LABEL = $(LABEL) + QUICK_TEST
# # endif 


# MACROS = EXT_SIM_INSERTED_TIMEOUT=10 -D$(COUNTRY) -D$(RF) -D$(OPTIONS) -D$(LANGUAGE) -D$(MODEM_TYPE) 
# MACROS += -D$(DISPLAY) -D$(TEST_MODE) -D$(OPTIONS_2) -D$(OPTIONS_3) -D$(OPTIONS_4) -DCOINS_MAX=$(COINS_MAX)
# MACROS += -D$(HARDWARE) -D$(CV) -D$(SMS_NOTIFICATION) -D__APP_DEBUG__

# # QA_PATH = Z:/Development
# # QA_PATH = //AZRDC03/Cellnets/Development
# # QA_DIRECTORY = $(QA_PATH)/SimPhony_V3_QA/SimPhony_Versions/Ver$(VERSION)
# # QA_WORK_VER = $(QA_PATH)/SimPhony_V3_QA/SimPhony_Versions/Work_Version

# QA_DIRECTORY = $(PATH_SIMPHONY_VERSIONS)/Ver$(VERSION)
# QA_WORK_VER =  $(PATH_SIMPHONY_VERSIONS)/Work_Version


# Target = $(NAME)$(LABEL)_$(OPTIONS)_$(OPTIONS_2)_$(OPTIONS_4)$(COINS_OPTION)_$(TEST_MODE)$(HW)$(VERSION)$(VS)$(SUFFIX)


# PORT = 12
# LOADER=$(VPATH)/BIN_Loader.exe 


# # THE_TARGET = SimPhony_Mexico_v-1-72-3-1-24
# # Target = $(THE_TARGET)__00.hex

# SourceList = main.c my_macros.c SysClock.c Interrupt.c App.c String.c RF12B.c Init.c UART.c Outputs.c
# SourceList += Command.c printf.c Inputs.c Status.c mem.c



# # ifeq ($(mt),SKIP__MANUFACTURE__TEST)	
# # Target = SimPhony_Mexico_SMT_00.hex
# # endif	


# #MicroType = 18F65J15
# MicroType = 18F6722 #18F25K20
# Compiler = #PICC18
# PointerWidth = CP24



# #def p = pipe

# #ObjectList = $(patsubst %.c, %.obj, $(wildcard *.c )))
# ObjectList = $(patsubst %.c, %.obj, $(SourceList)) 

# ifneq ($(f), p)
# $(Target) : $(ObjectList) 
# 	$(Compiler) -E $^ -O$@  -$(PointerWidth) -A$(Offset) -Q -$(MicroType)
# #	rm *.lst
# #	$(VPATH)/CLEAN.BAT
# #	Rev.bat $(Target)
# else
# $(Target) : $(ObjectList)
# 	$(Compiler) -E $^ -O$@ -$(PointerWidth) -A$(Offset) -Q -$(MicroType)  
# #	$(VPATH)/CLEAN.BAT
# #	WinPic800.exe -p -s -dPIC$(MicroType) $(Target) 
# #	C:\PROGRA~1\Soft-Log\IcpWin\ICP_Win.exe $(Target) /pd
# #	Rev.bat $(Target
# #	rm *.lst							  
# 	$(LOADER) $(PORT) 115200 $(Target)
# endif

# #-ASMLISTExecuting: "C:\HTSOFT\PIC18\bin\picc18.exe" -C -E"my_macros.cce" "my_macros.c" -O"my_macros.obj" -I"C:\HTSOFT\PIC18\include" -Zg9 -O -ASMLIST -CP24 -Q -MPLAB -18F672

# %.obj : %.c 
# 	$(Compiler) -C -E -D$(MACROS) $< -O$@ -$(PointerWidth) -O -Zg9 -Q -$(MicroType)

# *.obj: *.h


# c:
# 	rm -f *.obj *.lst *.sdb *.p1
# 	rm -f $(Target) 

# cp:
# 	cp $(Target) $(QA_WORK_VER)

# p:
# #	C:\WinPic800\WinPic800.exe -p -s -dPIC$(MicroType) $(Target)
# #	C:\PROGRA~1\Soft-Log\IcpWin\ICP_Win.exe $(Target) /p
# 	$(LOADER) $(PORT) 115200 $(Target)

# e:
# #	etg.bat
# 	etags *.c *.h ../SimPhony_Basic/*.c ../SimPhony_Basic/*.h


# FULL=$(patsubst %.hex,%__FULL.hex, $(Target))

# all: $(Target)
# 	bash $(VPATH)/CreateDir.sh $(QA_DIRECTORY)
# 	cp $(Target) $(QA_DIRECTORY) 
# 	bash ../Utilites/h2h.sh $(BOOT_LOADER) $(Target) > $(FULL)
# 	unix2dos $(FULL)
# 	cp $(FULL) $(QA_DIRECTORY) 
# 	$(VPATH)/CLEAN.BAT 


# alld: $(Target) 
# 	$(VPATH)/CreateDir.sh $(QA_WORK_VER) 
# 	cp $(Target) $(QA_WORK_VER) 
# 	bash ../Utilites/h2h.sh $(BOOT_LOADER) $(Target) > $(FULL)
# 	unix2dos $(FULL)
# 	cp $(FULL) $(QA_WORK_VER) 
# 	$(VPATH)/CLEAN.BAT


# ATTACH=$(COUNTRY).7z


# REMOVE_7Z:
# 	rm -f *.7z

# $(ATTACH):	
# 	7z a $(COUNTRY).7z *.hex


# smd:
# 	bash $(VPATH)/sendEMail.sh $(QA_WORK_VER) $(COUNTRY) $(ATTACH)  

# balld:
# 	./alld.sh

# bad: balld REMOVE_7Z $(ATTACH) smd

# #bad: $(ATTACH) smd



# # # 

# # # ,grigor@bezeqint.net
# # USERS=dima.development@gmail.com #,namatiev14@gmail.com
# # #USERS=abcd22@mail.ru namatiev14@gmail.com
# # #ATTACH=BallsVer_$(REVISION)_.7z
# # ATTACH=$(PROJECT_NAME).7z
# # EMAIL_CFG=./email.conf

# # $(ATTACH):
# # 	7z a $(PROJECT_NAME).7z *.bin


# # mt:
# # 	googletalk.exe /mailto $(USERS)

# # # msg:
# # # 	echo "`pwd`$(ATTACH)"

# # sm:
# # 	printf "\n %s\n\n\t%s" "See attachment" "---" | email -s " PinPonk. Version Update." -c $(EMAIL_CFG) \
# # 	 -a $(ATTACH) $(USERS)  

# # bsm: del ba $(ATTACH) sm



# # # 





# sm:
# 	printf "\n %s \n\n\t%s \n\n%s \n" "Kuku" "MUMU" | email -s "SimPhony. Versions Update." dima.development@gmail.com 

# # MEXICO
# # cd ../SimPhony_Mexico
# # make c
# # rm -f *.hex
# # make all 
# # make all HARDWARE=HARDWARE__SIM_LITE
# # make all HARDWARE=HARDWARE__VIA_SMC
# # # make all HARDWARE=HARDWARE__VIA_SMC RF=RF_CHANNEL 
# # # make all HARDWARE=HARDWARE__SIM_LITE RF=RF_CHANNEL OPTIONS=LOCKED_PHONE

# # 	HARDWARE=HARDWARE__VIA_SMC OPTIONS=TOPUP_COIN



# # 

